package com.exception;

import java.io.FileNotFoundException;

/*
测试异常的抛出
 */
public class Student {
    private Integer age;

    public Student() {
    }

    public Student(Integer age) {
        this.age = age;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) throws  IllegalAgeException {
        int i = age;
        if (i<0 || i>120){
            //当使用throw抛出一个非RuntimeException时，必须在当前方法上用throws声明该异常的抛出
           throw new IllegalAgeException("年龄不合法");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
